#!/usr/bin/php
<?php
/*
 * Copyright (C) 2013-2014 RuneAudio Team
 * http://www.runeaudio.com
 *
 * RuneUI
 * copyright (C) 2013-2014 - Andrea Coiutti (aka ACX) & Simone De Gregori (aka Orion)
 *
 * RuneOS
 * copyright (C) 2013-2014 - Simone De Gregori (aka Orion) & Carmelo San Giovanni (aka Um3ggh1U)
 *
 * RuneAudio website and logo
 * copyright (C) 2013-2014 - ACX webdesign (Andrea Coiutti)
 *
 * This Program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This Program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with RuneAudio; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.txt>.
 *
 *  file: command/airplay_toggle
 *  version: 1.3
 *  coder: Simone De Gregori
 *
 */
// common include
ini_set('display_errors', '1');
error_reporting(E_ALL);
ini_set('error_log', '/var/log/runeaudio/airplay_toggle.log');
define('APP', '/srv/http/app/');
// Connect to Redis backend
$redis = new Redis();
$redis->connect('/tmp/redis.sock');
$activePlayer = $redis->get('activePlayer');
include('/srv/http/app/libs/runeaudio.php');
// toggle playback
wrk_togglePlayback($redis, $activePlayer);
if ($activePlayer !== 'Airplay') {
    // set activePlayer
    $redis->set('activePlayer', 'Airplay');
    // send notify
    ui_notify('AirPlay', 'The player is locket by an incoming Airplay stream.');
} else {
    // send notify
    ui_notify('AirPlay', 'Airplay stream finished. Player unlocked.');
}
// update player view
ui_libraryHome($redis);
